package org.shoukaiseki.aliyun.captchasms.config;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import org.shoukaiseki.aliyun.sms.config.AliyunSmsConfigProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 手机号验证码验证
 * org.shoukaiseki.aliyun.sms.config.config.AlyunSmsCaptchaConfiguration
 * <br>
 *
 * @author shoukaiseki ブログ http://www.shoukaiseki.top/<br> E-メール jiang28555@Gmail.com<br>
 * @date 2020-12-05 17:33:21<br>
 */
@Configuration
public class CaptchaPhonenumberConfiguration {


    public static final String CAPTCHA_ALIYUN_SMS_PROP_BEAN_NAME ="captchaAliyunSmsConfigProperties";

    public static final String CAPTCHA_ALIYUN_ACS_CLIENT_BEAN_NAME ="captchaAliyunSmsAcsClient";

    @Bean(name = CAPTCHA_ALIYUN_SMS_PROP_BEAN_NAME)
    @ConfigurationProperties(prefix = "sks.aliyun.sms.captcha")
    public AliyunSmsConfigProperties captchaAliyunSmsConfigProperties(){
        return new AliyunSmsConfigProperties();
    }

    @Bean(name=CAPTCHA_ALIYUN_ACS_CLIENT_BEAN_NAME)
    public IAcsClient captchaAliyunSmsAcsClient(){
        AliyunSmsConfigProperties aliyunSmsConfigProperties = captchaAliyunSmsConfigProperties();
        DefaultProfile profile = DefaultProfile.getProfile(aliyunSmsConfigProperties.getRegionId(), aliyunSmsConfigProperties.getAccessKeyId(), aliyunSmsConfigProperties.getSecretAccessKey());
        IAcsClient client = new DefaultAcsClient(profile);
        return client;
    }

}

